let timer = null, app = getApp();
import { config } from "../../utils/config";
import { imgCompressSec } from "../../utils/img";

Page({
  data: {
    showPicker: false,
    columns: [],
    fileListImg: [],
    showPickerIndex: '',
    xiaonachangList: [],
    activeRowId: '',
    activeRowItem: {},
    activeXNCobj: {},
    isShowPickerWriteMoney: false,
    field: [],
    inputObj: {
      popupFileList: [],
      popupNotes: '',
    },

  },
  onLoad (option) {
    let that = this;
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      if (data.activeRowItem.tujingdian.length > 0) {
        data.activeRowItem.tujingdian = JSON.parse(data.activeRowItem.tujingdian);
      }
      data.activeRowItem.yuyueqingyunshijian = wx.$util.crtTimeFtt(data.activeRowItem.yuyueqingyunshijian, 'yyyy-MM-dd');
      that.setData({
        activeRowId: data.activeXiaoList,
        activeRowItem: data.activeRowItem,
        xiaonachangObj: data.xiaonachangObj,
        cailiaozhongleiList: data.cailiaozhongleiList,
        field: [
          { field_id: 'driver_start_img', label: '装货照片', type: 'picture', is_take_a_photo: true, compress: true, watermark: () => that.getWatermark(), is_null: false },
          { field_id: 'driver_start_mark', label: '备注', type: 'textarea' }
        ]
      }, () => {
        that.getXiaoNaChangList();
        let imgList = [];
        if (data.activeRowItem.xianchangzhaopian && data.activeRowItem.xianchangzhaopian.length > 0) {
          let imgArr = data.activeRowItem.xianchangzhaopian.split(','), baseURL = wx.getStorageSync('baseURL')
          imgArr.map(element => {
            imgList.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isImage: true,
              deletable: true,
            })
          })
        }
        let videoList = [];
        if (data.activeRowItem.shipin && data.activeRowItem.shipin.length > 0) {
          let shipinArr = data.activeRowItem.shipin.split(','), baseURL = wx.getStorageSync('baseURL')
          shipinArr.map(element => {
            videoList.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isVideo: true,
              deletable: true,
            })
          })
        }
        let zhuanghuozhaopian = [];
        if (data.activeRowItem.ZhuangHuoZhaoPian && data.activeRowItem.ZhuangHuoZhaoPian.length > 0) {
          let zhuanghuozhaopianArr = data.activeRowItem.ZhuangHuoZhaoPian.split(','), baseURL = wx.getStorageSync('baseURL')
          zhuanghuozhaopianArr.map(element => {
            zhuanghuozhaopian.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isVideo: true,
              deletable: true,
            })
          })
        }

        let XieHuoZhaoPian = [];
        if (data.activeRowItem.XieHuoZhaoPian && data.activeRowItem.XieHuoZhaoPian.length > 0) {
          let XieHuoZhaoPianArr = data.activeRowItem.XieHuoZhaoPian.split(','), baseURL = wx.getStorageSync('baseURL')
          XieHuoZhaoPianArr.map(element => {
            XieHuoZhaoPian.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isVideo: true,
              deletable: true,
            })
          })
        }
        that.setData({
          fileListImg: imgList,
          fileListVideo: videoList,
          zhuanghuozhaopian,
          XieHuoZhaoPian
        })
      })
    })
  },
  onShow () {
    this.setData({
      userName: wx.getStorageSync('user_name'),
      driver_car_name: wx.getStorageSync('driver_car_name'),
      nowData: wx.$util.formatYMD(new Date())
    })
  },
  onUnload () {
    clearTimeout(timer);
  },
  getMapDriver () {
    let that = this;
    wx.showLoading({ title: '正在加载中~', icon: "none" })
    // 有途经点
    let tuJingList = [], waypointsList = [];
    if (this.data.activeRowItem.tujingdian.length > 0) {
      this.data.activeRowItem.tujingdian.forEach(element => {
        tuJingList.push(`${element.latitude},${element.longitude}`)
      });
      if (tuJingList.length > 0) {
        waypointsList = tuJingList.join(";")
      }
    }
    wx.$post(2, 'map/tencent/ws/direction/driving', {
      from: `${that.data.activeRowItem.shouyundiweidu},${that.data.activeRowItem.shouyundijingdu}`,
      // waypoints: waypointsList,
      to: `${that.data.xiaonachangJWobj.destination_latitude},${that.data.xiaonachangJWobj.destination_longitude}`
    }, false, true).then(res => {
      wx.hideLoading();
      if (res.message != 'Success' && res.status != 0) return wx.$toast('路程报错');
      let { activeRowItem } = that.data;
      activeRowItem.yunshulicheng = res.result.routes[0].distance / 1000;
      activeRowItem.yunshuhaoshi = res.result.routes[0].duration;
      that.setData({ activeRowItem }, () => {
        that.calculateFees();// 有距离后计价
      })
    })
  },
  openLocation (e) {
    let { lat, lng } = e.currentTarget.dataset;
    // 打开地图查看位置
    let locationObj = {
      latitude: Number(lat),
      longitude: Number(lng),
    }
    wx.openLocation({
      ...locationObj,
      isSupportNavigation: true,
      complete (res) {
        console.log(res, '查看信息呢')
      }
    })
  },
  showPicker () {
    this.setData({ showPicker: !this.data.showPicker })
  },
  onConfirmPicker (e) {
    let { activeRowItem } = this.data;
    activeRowItem.chuzhichangsuo = this.data.xiaonachangObj[this.data.xiaonachangList[e.detail.index]]['xiaonachang;row_id'];
    activeRowItem.chuzhichangsuomingchen = this.data.xiaonachangObj[this.data.xiaonachangList[e.detail.index]]['xiaonachang;value'];
    this.setData({ activeXNCobj: this.data.xiaonachangObj[this.data.xiaonachangList[e.detail.index]], showPicker: !this.data.showPicker, activeRowItem }, () => {
      this.getDestination();// 获取消纳场JW
    })
  },
  navPushPageYiJia () {
    wx.navigateTo({
      url: '/SlagCar/WeiXin/WeiXin'
    })
  },
  chargeback () {
    if (!this.data.activeRowItem.row_id) return wx.$toast("订单丢失拉!!")
    let that = this;
    wx.showModal({
      title: '确定要退单？',
      success: (res) => {
        if (res.confirm) {
          wx.$post(5, `ZTAuth/CancelGrabWasteOrder/${that.data.activeRowItem.row_id}`, that.data.activeRowItem.row_id).then(res => {
            if (res.response.errcode != 0) return wx.$toast(res.response.errmsg);
            wx.$toast("退单成功");
            timer = setTimeout(() => {
              that.refreshOrder();
            }, 2000)
          })
        }
      },
    })
  },
  receivingOrders () {
    if (!this.data.activeRowItem.row_id) return wx.$toast("订单丢失拉!!");
    if (!this.data.activeXNCobj['xiaonachang;value']) return wx.$toast("尚未选择消纳场");
    let that = this, { activeRowItem } = this.data;
    wx.showModal({
      title: '确定要接单？',
      success: (res) => {
        if (res.confirm) {
          wx.$post(5, `ZTAuth/GrabWasteOrder/${that.data.activeRowItem.row_id}`, that.data.activeRowItem.row_id).then(res => {
            if (res.response.errcode != 0) return wx.$toast(res.response.errmsg);
            activeRowItem.tujingdian = JSON.stringify(that.data.activeRowItem.tujingdian);
            activeRowItem.dingdanzhuangtai = '抢单'
            activeRowItem.chepaihaoma = wx.getStorageSync('driver_car_row_id');
            activeRowItem.chepaihaoma_name = this.data.driver_car_name;
            that.setData({ activeRowItem }, () => { // 转换为JSON字符串
              that.editOrder(that.data.activeRowItem, '接单成功')// 修改订单数据/状态
            })
          })
        }
      },
    })
  },
  refreshOrder () {
    wx.showLoading({ title: '正在刷新', icon: "none" })
    wx.$get(5, 'ZTAuth/WasteOrder', { "row_id": this.data.activeRowItem.row_id }).then(res => {
      wx.hideLoading()
      if (res.response.errcode != 0) return wx.$toast(res.response.errmsg);
      if (res.data.row.length > 0) {
        let data = res.data.row[0];
        if (data.tujingdian.length > 0) {
          data.tujingdian = JSON.parse(data.tujingdian);
        }
        data.yuyueqingyunshijian = wx.$util.crtTimeFtt(data.yuyueqingyunshijian, 'yyyy-MM-dd');
        let imgList = [];
        if (data.xianchangzhaopian && data.xianchangzhaopian.length > 0) {
          let imgArr = data.xianchangzhaopian.split(','), baseURL = wx.getStorageSync('baseURL')
          imgArr.map(element => {
            imgList.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isImage: true,
              deletable: true,
            })
          })
        }
        let videoList = [];
        if (data.shipin && data.shipin.length > 0) {
          let shipinArr = data.shipin.split(','), baseURL = wx.getStorageSync('baseURL')
          shipinArr.map(element => {
            videoList.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isVideo: true,
              deletable: true,
            })
          })
        }

        let zhuanghuozhaopian = [];
        if (data.ZhuangHuoZhaoPian && data.ZhuangHuoZhaoPian.length > 0) {
          let zhuanghuozhaopianArr = data.ZhuangHuoZhaoPian.split(','), baseURL = wx.getStorageSync('baseURL')
          zhuanghuozhaopianArr.map(element => {
            zhuanghuozhaopian.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isVideo: true,
              deletable: true,
            })
          })
        }

        let XieHuoZhaoPian = [];
        if (data.XieHuoZhaoPian && data.XieHuoZhaoPian.length > 0) {
          let XieHuoZhaoPianArr = data.XieHuoZhaoPian.split(','), baseURL = wx.getStorageSync('baseURL')
          XieHuoZhaoPianArr.map(element => {
            XieHuoZhaoPian.push({
              url: baseURL + '/files/1164/' + element,
              name: 'element',
              isVideo: true,
              deletable: true,
            })
          })
        }
        this.setData({
          activeRowItem: data,
          fileListImg: imgList,
          fileListVideo: videoList,
          zhuanghuozhaopian,
          XieHuoZhaoPian
        }, () => {
          wx.$toast("订单已更新数据");
          wx.pageScrollTo({
            scrollTop: 0,
            duration: 300
          })
        })
      }
    })
  },
  submitOrdersMoney () {
    if (this.data.activeRowItem.dingdanzhuangtai == '抢单') {
      this.editOrder({ 'yufujine': this.data.activeRowItem.yufujine, "dingdanzhuangtai": "报价" }, "报价成功，等待客户支付预付款", () => { this.setData({ isShowPickerWriteMoney: !this.data.isShowPickerWriteMoney }) })
    }
    if (this.data.activeRowItem.dingdanzhuangtai == '装货') {
      this.editOrder({ 'YuKuanJinE': this.data.activeRowItem.YuKuanJinE, "BuChongJinE": this.data.activeRowItem.BuChongJinE, "dingdanzhuangtai": "补录费用" }, "补录费用报价成功，等待客户支付余额", () => { this.setData({ isShowPickerWriteMoney: !this.data.isShowPickerWriteMoney }) })
    }
  },
  advancePayment () {
    this.setData({
      isShowPickerWriteMoney: !this.data.isShowPickerWriteMoney,
      'activeRowItem.YuKuanJinE': Number(this.data.activeRowItem.Order_amount) - Number(this.data.activeRowItem.yufujine)
    })
  },
  departCar () {
    let that = this;
    wx.showModal({
      title: '确认出车？',
      success: (res) => {
        if (res.confirm) {
          that.editOrder({ "dingdanzhuangtai": "出车" }, "订单已修改为【出车】状态", () => {
            let isSendWXgps = wx.getStorageSync('isSendWXgps');
            if (!isSendWXgps) {
              let driver_car_name = wx.getStorageSync('driver_car_name');
              app.timeOutSendWXlocation(driver_car_name)
            }
          })
        }
      },
    })
  },
  carLoading () {
    let that = this;
    wx.showModal({
      title: '确认到达装货点装货？',
      success: (res) => {
        if (res.confirm) {
          // that.editOrder({ "dingdanzhuangtai": "装货" }, "装货成功")
          that.bindClosedepartShowPopup()
        }
      },
    })
  },
  depart () {
    let that = this;
    wx.showModal({
      title: '确认发车？',
      success: (res) => {
        if (res.confirm) {
          that.editOrder({ "dingdanzhuangtai": "发车" }, "订单已修改为【发车】状态")
        }
      },
    })
  },
  unloadGoods () {
    let that = this;
    wx.showModal({
      title: '确认到达目的地进行卸货？',
      success: (res) => {
        if (res.confirm) {
          // that.editOrder({ "dingdanzhuangtai": "卸货" }, "订单已修改为【卸货】状态")
          that.bindClosedepartShowPopup()
        }
      },
    })
  },
  complete () {
    let that = this;
    wx.showModal({
      title: '确认订单已完成？',
      success: (res) => {
        if (res.confirm) {
          that.editOrder({ "dingdanzhuangtai": "完成" }, "订单已完成!")
        }
      },
    })
  },
  editOrder (requestData, toast, cb) {
    let that = this;
    wx.showLoading({ title: '正在提交', icon: "none" })
    wx.$put(5, `ZTAuth/WasteOrder/${this.data.activeRowItem.row_id}`, requestData).then(res => {
      wx.hideLoading()
      if (res.response.errcode != 0) return wx.$toast(res.response.errmsg);
      wx.$toast(toast);
      if (cb) cb();
      timer = setTimeout(() => {
        that.refreshOrder();
      }, 2000)
    })
  },
  getXiaoNaChangList () {
    let that = this;
    let fieldList = [{ "CompareValue": this.data.activeRowItem.jijiadanwei, "CompareWith": "e_lajidingdan_xiaonachang_jijiabiao.JiJiaDanWei", "Operator": "=", "or": 0 },
    { "CompareValue": this.data.activeRowItem.cheliangleibie, "CompareWith": "e_lajidingdan_xiaonachang_jijiabiao.CheLiangLeiBie", "Operator": "=", "or": 0 },
    { "CompareValue": this.data.activeRowItem.chexing, "CompareWith": "e_lajidingdan_xiaonachang_jijiabiao.CheXing", "Operator": "=", "or": 0 },
    { "CompareValue": this.data.activeRowItem.chexiangrongji, "CompareWith": "e_lajidingdan_xiaonachang_jijiabiao.CheXiangRongJi", "Operator": "=", "or": 0 },
    { "CompareValue": this.data.activeRowItem.cailiaozhonglei, "CompareWith": "e_lajidingdan_xiaonachang_jijiabiao.CaiLiaoLeiBie", "Operator": "=", "or": 0 }];
    if (this.data.activeRowItem.dingdanzhuangtai != '下单') {
      fieldList.push({
        "CompareValue": this.data.activeRowItem.chuzhichangsuo, "CompareWith": "e_lajidingdan_xiaonachang_jijiabiao.xiaonachang", "Operator": "=", "or": 0
      })
    }
    this.getCustomData('e_lajidingdan_xiaonachang_jijiabiao', fieldList).then(res => {
      let list = res || [], arrAy = {}, arr = [];
      if (that.data.activeRowItem.dingdanzhuangtai == '下单') {
        list.map(item => {
          arr.push(item['xiaonachang;value'])
          arrAy[item['xiaonachang;value']] = item;
        })
        that.setData({ xiaonachangList: arr, xiaonachangObj: arrAy })
      } else {
        that.setData({ activeXNCobj: list[0] }, () => {
          that.getDestination();
        })
      }
    })
  },
  writeMoney (e) {
    let { code } = e.currentTarget.dataset, value = e.detail;
    this.setData({ [`activeRowItem.${code}`]: value }, () => {
      this.setData({
        'activeRowItem.YuKuanJinE': Number(this.data.activeRowItem.Order_amount) - Number(this.data.activeRowItem.yufujine) + Number(this.data.activeRowItem.BuChongJinE)
      })
    })
  },
  getDestination () { // 根据属性去换消纳场列表
    let fieldList = [{ "CompareValue": this.data.activeXNCobj['xiaonachang;row_id'], "CompareWith": "all_destination.row_id", "Operator": "=", "or": 0 }];
    this.getCustomData('all_destination', fieldList).then(res => {
      this.setData({
        xiaonachangJWobj: res.length > 0 ? res[0] : {}
      }, () => {
        if (this.data.activeRowItem.dingdanzhuangtai == '下单') {
          this.getMapDriver()
        }
      })
    })
  },
  //获取diy数据
  getCustomData (table_id, where) {
    let url = 'DynamicQuery/query_dynamic_v3',
      post = { limit: 0, page: 1, table_id, oby: `${table_id}.row_id` };
    where && (post.SearchWhere = { filters: where, type: 'and' });
    return new Promise(resolve => {
      wx.$post(3, url, post).then(res => {
        if (res.errcode != 0) return;
        resolve(res.data.row)
      })
    })
  },
  // 集中计价
  calculateFees () {
    let { activeRowItem, activeXNCobj } = this.data;
    let url = 'ZTAuth/WasteOrderCalculateFees',
      data = {
        "RiQi": "", // 日期
        "LiCheng": 0, //里程
        "HangChengShiJian": 0,  //行程时间
        "YiJiQuYu": 0,  // 一级收运区域
        "ErJiQuYu": 0,  // 二级收运区域
        "SanJiQuYu": 0, // 三级收运区域
        "DunShu": 0,    // 吨数
        "FangShu": 0,   // 方数
        "CaiLiaoLeiBie": 0, // 材料类别
        "YunShuCheLiangLeiBie": 0,  // 运输车辆类别
        "YunShuCheLiangCheXing": 0, // 运输车辆车型
        "YunShuCheLiangRongJi": 0,  // 运输车辆容积
        "JiSuanDanWei": "车", // 计算单位(车/吨/方)
        "CheCi": 0,   // 车次
        "XiaoNaChang": 0, // 消纳场
      };

    // 日期
    data.RiQi = activeRowItem.yuyueqingyunshijian;

    // 里程、行程时间
    data.LiCheng = activeRowItem.distance;
    data.HangChengShiJian = activeRowItem.shijian;

    // 消纳场
    data.XiaoNaChang = activeXNCobj['xiaonachang;row_id'];

    // 收运区域
    data.YiJiQuYu = activeRowItem.shouyunyijiquyu;
    data.ErJiQuYu = activeRowItem.shouyunerjiquyu;
    data.SanJiQuYu = activeRowItem.shouyunsanjiquyu;

    // 吨数、方数、材料类别
    data.DunShu = activeRowItem.yuguzhongliang;
    data.FangShu = activeRowItem.yugutiji;
    data.CaiLiaoLeiBie = activeRowItem.cailiaozhonglei

    // 车次
    data.CheCi = activeRowItem.checishu;
    data.YunShuCheLiangLeiBie = activeRowItem.cheliangleibie
    data.YunShuCheLiangCheXing = activeRowItem.chexing
    data.YunShuCheLiangRongJi = activeRowItem.chexiangrongji
    data.JiSuanDanWei = activeRowItem.jijiadanwei

    wx.$post(5, url, data).then(res => {
      if (res.errcode != 0) return
      let row = res.data.row && res.data.row[0] || {},
        priceArr = [{
          details: [
            {
              cost_name: row.total_cost_name,
              cost_value: row.total_cost_value,
              mark: null
            },
            {
              cost_name: row.total_mileage_name,
              cost_value: row.total_mileage_value,
              mark: null
            },
          ]
        }, ...row.total_details];
      activeRowItem.Order_amount = row.total_cost_value
      this.setData({ priceArr, activeRowItem }, () => {
        this.saveFees();
      })
    })
  },
  // 保存费用
  saveFees (pid) {
    let { priceArr, activeRowItem } = this.data,
      fees = [];
    priceArr.forEach(item => {
      item.details.forEach(ite => {
        item.cost_project_name && fees.push({
          "parent_row_id": activeRowItem.row_id,
          "feiyongmingchen": ite.cost_name,
          "Order_amount": ite.cost_value || 0,
          "beizhu": item.mark || "",
          "is_used": true
        })
      })
    });
    return new Promise(resolve => {
      let url = 'ZTAuth/WasteOrderFees'
      wx.$post(5, url, fees).then(res => {
        if (res.errcode != 0) return
        resolve();
      })
    })
  },
  //获取水印信息
  getWatermark () {
    return new Promise(resolve => {
      this.initData().then(() => {
        let { address, nowTime, driver_car_name } = this.data;
        let arr = [{
          content: address,
          font: '14px serif',
          position: {
            bottom: 20,
            left: 15
          }
        },
        {
          content: driver_car_name,
          font: '24px serif',
          position: {
            bottom: 50,
            left: 15
          }
        },
        {
          content: nowTime,
          font: '25px serif',
          position: {
            bottom: 80,
            left: 15
          }
        }];
        resolve(arr)
      });
    })
  },
  //初始化数据
  initData () {
    return new Promise(resolve => {
      let nowTime = wx.$util.formatDate(new Date(), 'yyyy-MM-dd HH:mm');
      wx.showLoading();
      this.wxLocation().then(res => {
        wx.hideLoading();
        let { address, location, formatted_addresses } = res.result;
        address = formatted_addresses && formatted_addresses.recommend || address;
        this.setData({ address, location, nowTime })
        resolve();
      }, () => {
        wx.hideLoading();
        wx.showModal({
          title: '定位服务未打开',
          content: '请在系统设置中打开位置授权，以便我们为您提供更好的服务',
          confirmText: '确定',
          showCancel: false,
          success: (res) => {
            if (res.confirm) {
              wx.navigateTo({ url: '/SlagCar/OpenLocationGuide/OpenLocationGuide' })
            }
          },
        });
      })
    })
  },
  //  获取当前位置
  wxLocation () {
    return new Promise((resolve, reject) => {
      wx.$getLocation().then(res => {
        wx.showLoading({ title: '正在转换位置信息', mask: true })
        this.mapGeocoder(res).then(result => {
          wx.hideLoading();
          resolve(result);
        })
      }, reject)
    })
  },

  //腾讯地图api逆地址转换
  mapGeocoder (latlng) {
    let url = 'map/tencent/ws/geocoder/location';
    let { latitude, longitude } = latlng;
    return new Promise(resolve => {
      wx.$post(2, url, {
        "key": config.mapKey,
        "location": `${latitude},${longitude}`,
        "get_poi": "",
        "poi_options": "",
        "output": "",
        "callback": ""
      }, false, true).then(res => {
        resolve(res)
      })
    })
  },
  bindClosedepartShowPopup () {
    this.setData({ departShowPopup: !this.data.departShowPopup })
  },
  bindSubmit () {
    if (this.data.inputObj.popupFileList.length <= 0) return wx.$toast(this.data.activeRowItem.dingdanzhuangtai == '出车' ? '请先上传装货照片' : '请先上传卸货照片')
    if (this.data.loading) return
    this.data.loading = true;
    wx.showLoading({ mask: true });
    let nowTime = wx.$util.formatDate(new Date(), 'yyyy-MM-dd HH:mm');
    let { popupFileList, popupNotes } = this.data.inputObj, { activeRowItem } = this.data, that = this;;
    let list = [];
    popupFileList.forEach(item => { list.push(item.data); })
    this.wxLocation().then(res => {
      wx.hideLoading();
      let { address, location, formatted_addresses } = res.result;
      address = formatted_addresses && formatted_addresses.recommend || address;
      activeRowItem.tujingdian = JSON.stringify(that.data.activeRowItem.tujingdian);
      if (that.data.activeRowItem.dingdanzhuangtai == '出车') {
        activeRowItem.ZhuangHuoDiZhi = address;
        activeRowItem.ZhuangHuoJingDu = location.lng;
        activeRowItem.ZhuangHuoShiJian = nowTime;
        activeRowItem.ZhuangHuoWeiDu = location.lat;
        activeRowItem.ZhuangHuoZhaoPian = list.join(",");
        activeRowItem.dingdanzhuangtai = '装货';
      } else {
        activeRowItem.XieHuoDiZhi = address;
        activeRowItem.XieHuoJingDu = location.lng;
        activeRowItem.XieHuoShiJian = nowTime;
        activeRowItem.XieHuoWeiDu = location.lat;
        activeRowItem.XieHuoZhaoPian = list.join(",");
        activeRowItem.dingdanzhuangtai = '卸货';
      }
      that.editOrder(activeRowItem, that.data.activeRowItem.dingdanzhuangtai == '出车' ? '订单已修改为【装货】状态' : '订单已修改为【卸货】状态', () => {
        that.bindClosedepartShowPopup();
      })// 修改订单数据/状态
    }, () => {
      wx.hideLoading();
      that.setData({ loading: false })
      wx.showModal({
        title: '定位服务未打开',
        content: '请在系统设置中打开位置授权，以便我们为您提供更好的服务',
        confirmText: '确定',
        showCancel: false,
        success: (res) => {
          if (res.confirm) {
            wx.navigateTo({ url: '/SlagCar/OpenLocationGuide/OpenLocationGuide' })
          }
        },
      });
    })
  },
  inputDelete (e) {
    let list = this.data.inputObj.popupFileList;
    let newList = list.filter(item => item.url != e.detail.file.url);
    this.setData({ 'inputObj.popupFileList': newList })
  },
  inputAfterRead (e) {
    let files = e.detail.file, that = this, proArr = [], list = [], uploadFn = wx.$uploadReq
    new Promise(resolve => {
      files.tempFilePath = files.url;
      let fn = () => this.getWatermark();
      fn().then(async ops => {
        wx.showLoading({ title: '正在压缩图片', mask: true });
        await imgCompressSec(files, ops, that).then(res => {
          wx.hideLoading()
          proArr.push(uploadFn(res.tempFilePath))
          resolve();
        });
      }).catch((res) => { })
    }).then(() => {
      Promise.all(proArr).then(res => {
        if (res.length > 0) {
          if (res[0].data.row.length > 0) {
            let { row } = res[0].data;
            list.push({
              url: row[0].data,
              data: row[0].filename,
              name: row[0].shortName,
              isImage: true,
              deletable: true,
            })
          }
        }
        that.setData({ 'inputObj.popupFileList': that.data.inputObj.popupFileList.concat(list) })
      })
    })
  },
  inputObjNotes (e) {
    this.setData({ 'inputObj.popupNotes': e.detail })
  }
})